#include "wuEnanitoStaticKinect.h"

wuEnanitoStaticKinect::wuEnanitoStaticKinect()
{
}

wuEnanitoStaticKinect::~wuEnanitoStaticKinect()
{
}

void wuEnanitoStaticKinect::setup(ofxBox2d * _box2d, int _vw, int _vh, int _x, int _y)
{
		wuHumanoid::setup(_box2d, _vw, _vh, _x, _y);
		myFBO.allocate(vw, vh, GL_RGBA);
//		myFBO.clear(0, 0, 0, 0);
		mask.allocate(vw,vh, OF_IMAGE_GRAYSCALE);
		scale.x = scale.y = 1.0;
}

void wuEnanitoStaticKinect::update(Skeleton _skel, unsigned char* colorSkin, unsigned char* graySkin)
{
	wuHumanoid::setSkel( _skel);

	if (skel.bDetected)
	{
		// crop bitmap
		skin.crop(colorSkin, graySkin, vw, vh);
		mask.setFromPixels( graySkin, vw, vh, OF_IMAGE_GRAYSCALE);
//		MakeFBOimage();
	}

//	wuHumanoid::update();
}

void wuEnanitoStaticKinect::draw(bool bDrawlines, int _offX)
{
	wuHumanoid::draw(bDrawlines, _offX);

    // pinta skin
	if (skel.bDetected)
	{
		ofPushMatrix();
			ofEnableAlphaBlending();
			ofSetColor(255, 255, 255, 255);
			skin.draw(framePos.x+_offX, framePos.y, vw*scale.x, vh*scale.y);
			ofDisableAlphaBlending();
		ofPopMatrix();
	}
}

void wuEnanitoStaticKinect::MakeFBOimage()
{
    //  2 body pieces minimum
	if (skel.bDetected)
	{

		wuEnte::myFBO_begin();

		ofPushMatrix();
			ofEnableAlphaBlending();
			ofSetColor(255, 255, 255, 255);
			mask.draw(framePos.x, framePos.y, vw*scale.x, vh*scale.y);
			ofDisableAlphaBlending();
		ofPopMatrix();

		wuEnte::myFBO_end();

	}

}
